package com.indexingsystem.boss.dync.datasource;
/*package com.indexingsystem.boss.dync.datasource;

import java.lang.reflect.Method;

import org.apache.log4j.Logger;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.aop.AfterReturningAdvice;
import org.springframework.aop.MethodBeforeAdvice;
import org.springframework.aop.ThrowsAdvice;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class DataSourceAdvice implements MethodBeforeAdvice, AfterReturningAdvice, ThrowsAdvice {
	// log4j
	private static Logger	log	= Logger.getLogger( DataSourceAdvice.class );

	// service方法执行之前被调用
	public void before(Method method, Object[] args, Object target) throws Throwable {
		log.info( "切入点: " + target.getClass().getName() + "类中" + method.getName() + "方法" );
		if (method.getName().startsWith( "add" ) || method.getName().startsWith( "insert" ) || method.getName().startsWith( "delete" ) || method.getName().startsWith( "create" ) || method.getName().startsWith( "increase" ) || method.getName().startsWith( "decrease" )
				|| method.getName().startsWith( "update" ) || method.getName().startsWith( "immediate" ) || method.getName().startsWith( "edit" )) {
			log.info( "切换到: master" );
			DynamicDataSourceHolder.setMaster();
		} else {
			log.info( "切换到: slave" );
			DynamicDataSourceHolder.setSlave();
		}
	}

	// service方法执行完之后被调用
	public void afterReturning(Object var1, Method var2, Object[] var3, Object var4) throws Throwable {
		DynamicDataSourceHolder.setMaster();
	}

	// 抛出Exception之后被调用
	public void afterThrowing(Method method, Object[] args, Object target, Exception ex) throws Throwable {
		DynamicDataSourceHolder.setSlave();
		log.info( "出现异常,切换到: slave" );

	}
}*/